using System;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace BassMati.Client
{
	/// <summary>
	/// Summary description for TraceExceptionFormatter.
	/// </summary>
	public class TraceFormatter
	{
		private TraceFormatter ( )
		{ }

		// Matches 3 blanks at the beginning of a line.
		protected static Regex stacktraceRegex = new Regex ( "^   ", RegexOptions.Multiline );
		// Defines the line end sequence.
		protected const string eol = "\r\n";
		
		public static string Format ( System.Exception e )
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder ( );
			sb.Append ( e.Message );
			sb.Append ( eol );
			sb.Append ( stacktraceRegex.Replace( e.StackTrace, new string( ' ', Trace.IndentSize * (Trace.IndentLevel + 1))));
			return sb.ToString ();
		}
	}
}
